<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>生成菜单</title>
    <link rel="stylesheet" href="../css/common.css">
    <style>
        .nav{
            width: 100vw;
            height: 40px;
            background: #cccccc;
            margin: 100px auto;
        }
        .title{
            height: 60px;
            width: 140px;
            background: #369;
            color: #ffffff;
            margin-left: 100px;
            transform: translate(0px,-10px) skewX(-15deg);
            text-align: center;
            line-height: 60px;
            font-size: 20px;
        }
        .list{
            margin-left: 30px;
        }
        .list li{
            width: 100px;
            height: 30px;
            margin: 10px;
            transform: translate(0px,-5px);
            text-align: center;
            line-height: 30px;
            color: #ffffff;
            cursor: pointer;
            position: relative;
        }
        .list li:hover{
            border-bottom: 3px solid #369;
        }
        .hot{
            position: absolute;
            right: -4px;
            top: -4px;
            width: 40px;
            height: 16px;
            background: orangered;
            border-radius: 3px;
            font-size: 12px;
            line-height: 16px;
        }
    </style>
</head>
<body>
    <div class="nav flex">
        <div class="title">课程栏目</div>
        <ul class="list flex">
            <!-- <li>Web
                <div class="hot">HOT</div>
            </li>
            <li>Java
                <div class="hot">HOT</div>
            </li>
            <li>Big Data</li>
            <li>Cloud</li>
            <li>AI</li> -->
        </ul>
    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
    <script>
        $.get('./data/menu.json',res=>{
            // console.log(res.data);
            //获取菜单项的名称
            let list = res.data.map(r=>r.name)
            // console.log(list);
            
            //循环数组，创建对应的li标签，并添加到页面中
            list.forEach(r => {
                //创建li标签
                let li = $('<li/>')
                //text() -> innerText
                //html() -> innerHTML
                li.html(r)
                //jq:append()方法 -> js:appendChild()
                $('.list').append(li)
            });
            //:eq(2) 表示获取索引为2的li
            //:lt(2) 表示获取索引小于2的li
            //:gt(2) 表示获取索引大于2的li

            //前两个li标签里面添加hot标签
            $('.list>li:lt(2)').append($('<div/>').html('HOT').addClass('hot'))
        })
    </script>
</body>
</html>